package com.study.controller;

import com.study.domain.Address;
import com.study.domain.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/hello")
public class HelloController {
    @RequestMapping(path = "/say")
    public String sayHello() {
        return "success";
    }

    @RequestMapping(path = "/sayWithParm")
    public String sayHello(String name) {
        System.out.println(name);
        return "success";
    }

    @RequestMapping(path = "/submitBean", method = RequestMethod.POST)
    public String submitBean(User user) {
        System.out.println(user);
        return "success";
    }

    @RequestMapping(path = "/testModelAttribute", method = RequestMethod.POST)
    public String testModelAttribute(User user) {
        System.out.println(user);
        return "success";
    }

    @ModelAttribute
    public User getModel(String name) {
        User user = new User();
        user.setAddress(new Address());
        user.setAge(20);
        user.setId("123");
        user.setName(name);
        return user;
    }


    @RequestMapping(path = "/testSession")
    public String testSession(Model model) {
        model.addAttribute("abc",model);
        return "success";
    }
}
